package com.hj.saapp.common.utils;

import android.app.ProgressDialog;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;


import com.hj.saapp.R;
import com.hj.saapp.bean.MultipleListDialogBean;
import com.hj.saapp.control.listener.ListDialogListener;
import com.hj.saapp.control.listener.ListHorizontalDialogListener;
import com.hj.saapp.view.DefaultingDialog;
import com.hj.saapp.view.ListBottomDialog;
import com.hj.saapp.view.ListHorizontalDialog;
import com.hj.saapp.view.ListMultipleDialog;

import java.util.ArrayList;
import java.util.List;

/**
 * 类说明：
 *
 * @author YZ
 * @version 1.0
 * @date May 26, 2015
 */

public class DialogUtil {


    private ProgressDialog progressDialog = null;

    private FragmentActivity activity;

    private ListMultipleDialog listMultipleDialog;

    private ListHorizontalDialog listHorizontalDialog;

    private ListBottomDialog listBottomDialog = null;


    private static DialogUtil dialogUtil = null;

    private DialogUtil() {

    }

    public void setActivity(FragmentActivity activity) {
        this.activity = activity;
    }

    public static DialogUtil getInstance() {
        if (dialogUtil == null) {
            dialogUtil = new DialogUtil();
        }

        return dialogUtil;
    }

    /**
     * 单一按键提示框
     *
     * @param title                 提示
     * @param onDialogClickListener 点击
     * @see [类、类#方法、类#成员]
     */
    public void showSoleDialog(String title, DefaultingDialog.OnDialogClickListener onDialogClickListener, boolean isCancelable) {

        showDialog(title,
                null,
                null,
                StringUtils.getStringById(R.string.dialog_verify),
                onDialogClickListener, isCancelable);
    }

    public void showSoleDialog(String title, String negativeStr, DefaultingDialog.OnDialogClickListener onDialogClickListener, boolean isCancelable) {
        showDialog(title, null, null, negativeStr, onDialogClickListener, isCancelable);
    }

    /**
     * 两个按键提示框
     *
     * @param title                 题目
     * @param positiveStr           确定按键文字
     * @param negativeStr           取消按键文字
     * @param onDialogClickListener 点击
     * @see [类、类#方法、类#成员]
     */
    public void showTwoDialog(String title, String positiveStr, String negativeStr,
                              DefaultingDialog.OnDialogClickListener onDialogClickListener, boolean isCancelable) {
        showDialog(title, null, positiveStr, negativeStr, onDialogClickListener, isCancelable);
    }

    /**
     * 带message提示框
     *
     * @param title                 题目
     * @param content               内容
     * @param positiveStr           确定按键文字
     * @param negativeStr           取消按键文字
     * @param onDialogClickListener 点击
     * @see [类、类#方法、类#成员]
     */
    public void showMessageDialog(String title, String content, String positiveStr, String negativeStr,
                                  DefaultingDialog.OnDialogClickListener onDialogClickListener, boolean isCancelable) {
        showDialog(title, content, positiveStr, negativeStr, onDialogClickListener, isCancelable);
    }

    private void showDialog(String title, String content, String positiveStr, String negativeStr,
                            final DefaultingDialog.OnDialogClickListener onDialogClickListener, boolean isCancelable) {


        if (activity == null) {
            return;
        }
        if (activity.isFinishing()) {
            return;
        }

        final DefaultingDialog dialog = new DefaultingDialog(activity, R.style.DefaultingDialog, title, content, positiveStr, negativeStr, isCancelable);
        dialog.setCancelable(false);
        dialog.setOnDialogClickListener(new DefaultingDialog.OnDialogClickListener() {
            @Override
            public void onPositiveClickListener() {
                if (onDialogClickListener != null) {
                    onDialogClickListener.onPositiveClickListener();
                }
            }

            @Override
            public void onNegativeClickListener() {
                if (onDialogClickListener != null) {
                    onDialogClickListener.onNegativeClickListener();
                }
            }
        });
        FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
        dialog.show(ft, "df");

    }

}
